/**
 * @Author: Sagan
 * @Date: 2020/09/19 14:06
 */
package module

import (
	"gitee.com/big_meteor/godash/lang"
	"gitee.com/big_meteor/godash/validate/constant"
	"gitee.com/big_meteor/godash/validate/function"
	"reflect"
)

// 是否为email地址
// 支持的类型：string
func Email(v interface{}) (bool, error) {
	var kind reflect.Kind
	v, kind = lang.GetValue(v)

	if reflect.String != kind {
		return false, constant.ERROR_EMAIL_UDT
	}

	return function.Email(v.(string)), nil
}

// 是否为字母
// 支持的类型：string
func Alpha(v interface{}) (bool, error) {
	var kind reflect.Kind
	v, kind = lang.GetValue(v)

	if reflect.String != kind {
		return false, constant.ERROR_ALPHA_UDT
	}

	return function.Alpha(v.(string)), nil
}

// 是否为字母和数字
// 支持的类型：string
func AlphaNum(v interface{}) (bool, error) {
	var kind reflect.Kind
	v, kind = lang.GetValue(v)

	if reflect.String != kind {
		return false, constant.ERROR_ALPHA_NUM_UDT
	}

	return function.AlphaNum(v.(string)), nil
}

// 是否为字母和数字，下划线_及破折号-
// 支持的类型：string
func AlphaDash(v interface{}) (bool, error) {
	var kind reflect.Kind
	v, kind = lang.GetValue(v)

	if reflect.String != kind {
		return false, constant.ERROR_ALPHA_DASH_UDT
	}

	return function.AlphaDash(v.(string)), nil
}
